package com.example.xinli.controller;

import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.domain.vo.ZidongsiweiSubmitVo;
import com.example.xinli.service.IRecordService;
import com.example.xinli.service.IUserService;
import com.example.xinli.service.IZidongsiweiService;
import com.example.xinli.utils.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@Slf4j
@RequestMapping("/zidongsiwei")
public class ZidongsiweiController {

    @Autowired
    private IZidongsiweiService zidongsiweiService;

    // 获取用户的自动思维列表
    @RequestMapping("/getAllUserZidongsiwei")
    @ResponseBody
    public ResponseBean getAllUserZidongsiwei(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        token = token.split(" ")[1];
        String userId = TokenUtil.getId(token);
        return zidongsiweiService.getAllUserZidongsiwei(userId);
    }

    // 上传自动思维
    @RequestMapping("/submitZidongsiwei")
    @ResponseBody
    public ResponseBean submitZidongsiwei(HttpServletRequest request, @RequestBody ZidongsiweiSubmitVo zidongsiweiSubmitVo) {
        return zidongsiweiService.submitZidongsiwei(zidongsiweiSubmitVo);
    }
}

